package com.archetypus.projectschedule.web.activities.cmd;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.archetypus.projectschedule.common.Configuration;
import com.archetypus.projectschedule.common.dto.activities.ActivityListHandler;
import com.archetypus.projectschedule.common.dto.projects.Project;
import com.archetypus.projectschedule.common.dto.projects.ProjectKey;
import com.archetypus.projectschedule.common.exceptions.ProjectSchedulerException;
import com.archetypus.projectschedule.web.activities.bd.ActivityBD;
import com.archetypus.projectschedule.web.activities.bd.IActivityBD;
import com.archetypus.projectschedule.web.common.cmd.ICommand;
import com.archetypus.projectschedule.web.projects.bd.IProjectBD;
import com.archetypus.projectschedule.web.projects.bd.ProjectBD;

public class ListActivityCmd implements ICommand {

	public void execute(HttpServletRequest request, HttpServletResponse response)throws ProjectSchedulerException {
		int projectId = Integer.parseInt(request.getParameter("project"));
		
		Project project = new Project();
		project.setProjectKey(new ProjectKey(projectId));
		
		IProjectBD projectBD = new ProjectBD();
		Project selectedProject = projectBD.findProject(project);
		
		IActivityBD activityBD = new ActivityBD();
		ActivityListHandler listHandler = activityBD.listActivitiesByProject(project);
		
		selectedProject.setDetail(listHandler.getList());
		
		request.setAttribute("project", selectedProject);
		request.setAttribute("projectDetail", listHandler.getList());
		request.setAttribute("pageSize", Configuration.getInstance().get("pageSize"));
	}

}
